from concurrent.futures import ThreadPoolExecutor, as_completed, futures_wait

from threading import Lock
import time


lock2 = Lock()
count = 0



def f1():

    global count

    with lock2:

        count += 1
        _count = count

    time.sleep(1)

    print(f"f1-{_count}执行完毕")

    if _count % 100 == 0:

        print(f"_count-{_count}分割线------------------------------------------")



def main():

    with ThreadPoolExecutor(max_workers=500) as executor:

        futures: list = [executor.submit(f1) for i in range(300)]
        futures_wait(futures, return_when="ALL_COMPLETED")

        print("所有任务执行完毕")



if __name__ == "__main__":
    main()


# import asyncio

# count = 0

# async def f1():

#     global count

#     count += 1
#     _count = count

#     await asyncio.sleep(1)

#     print(f"f1-{_count}执行完毕")

#     if _count % 100 == 0:

#         print(f"_count-{_count}分割线-------")



# async def main():

#     tasks = [asyncio.create_task(f1()) for i in range(300)]

#     await asyncio.gather(*tasks)

#     print("所有任务执行完毕")



# if __name__ == "__main__":

#     asyncio.run(main())

